#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    long long n, k, ret = 0;
    cin >> n >> k;
    vector<long long> arr(n), sum(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    sort(arr.begin(), arr.end());
    sum[0] = arr[0];
    for (int i = 1; i < n; i++) sum[i] = sum[i - 1] + arr[i];
    for (int left = 0, right = 0; right < n;)
    {
        int mid = (right + left) / 2;
        long long sumk = sum[right] - sum[mid] - (mid >= 1 ? sum[mid - 1] : 0) + (left >= 1 ? sum[left - 1] : 0) - arr[mid] * (right + left - 2 * mid);
        if (sumk <= k) ret = max((long long)right - left + 1, ret), right++;
        else left++;
    }
    cout << ret;
    return 0;
}